package cn.gson.crm.controller;

import cn.gson.crm.model.dao.RoleDao;
import cn.gson.crm.model.pojos.*;
import cn.gson.crm.model.service.DeptService;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/DeptController")
public class DeptController {
    @Autowired
    DeptService deptService;
    @Autowired
    RoleDao roleDao;
    @RequestMapping("/ContractMethod")
    @ResponseBody
    public List<Dept> selectdet(Integer did){
        return deptService.selectdet(did);
    };
    @RequestMapping("/ContractMethod2")
    @ResponseBody
    //根据部门id查询相对应职务
    public List<Role> selectrow(Integer did){
        return deptService.selectrow(did);
    };
    @RequestMapping("/ContractMethod3")
    @ResponseBody
    //查询全部角色
    public List<Role> selectrowquan(){
        return deptService.selectrowquan();
    };
    @RequestMapping("/ContractMethod4")
    @ResponseBody
    //给部门新增角色
    public void save(String positionList){
        deptService.save(positionList);
    }
    @RequestMapping("/ContractMethod5")
    @ResponseBody
    //查询所有的功能组
    public List<Functions> selectfun(){
        return deptService.selectfun();
    };
    @RequestMapping("/ContractMethod6")
    @ResponseBody
    //根据部门查询功能组
    public List<Integer> selectwherfun(Integer did){
        return deptService.selectwherfun(did);
    };
    @RequestMapping("/ContractMethod7")
    @ResponseBody
    //给部门授权功能
    public void busave(String json){
        deptService.busave(json);
    }
    @RequestMapping("/ContractMethod8")
    @ResponseBody
    //根据部门id查询功能组和功能
    public List<Function> selectfuntis(Integer did){
        return  deptService.selectfuntis(did);
    };
    @RequestMapping("/ContractMethod9")
    @ResponseBody
    //查询所有功能
    public List<Integer> selectgongsuoy(Integer jid){
        return deptService.selectgongsuoy(jid);
    };
    @RequestMapping("/ContractMethod10")
    @ResponseBody
    //给功能组加添加功能
    public void savegongge(String json){
       deptService.savegongge(json);
    }
    @RequestMapping("/ContractMethod11")
    @ResponseBody
    //查询所有部门
    public List<Dept> selectdeptd(){
        return deptService.selectdeptd();
    };
    @RequestMapping("/ContractMethod12")
    @ResponseBody
    //新增部门
    public void savedept(@RequestBody Dept dept){
        deptService.savedept(dept);
    }
    @RequestMapping("/ContractMethod13")
    @ResponseBody
    //根据部门名称查询部门
    public List<Dept> selectbuname(String dname){
        return  deptService.selectbuname(dname);
    };
    @RequestMapping("/ContractMethod14")
    @ResponseBody
    //根据部门查询此部门下有没有员工
    public List<User> selectuser(Integer did){
        return deptService.selectuser(did);
    };
    @RequestMapping("/ContractMethod15")
    @ResponseBody
    //删除部门
    public void deletedept(Long did){
        deptService.deletedept(did);
    }

    @RequestMapping("/ContractMethod16")
    @ResponseBody
    //根据部门id查询上级部门
    public List<Dept> selectdepet4(Integer did){
        return  deptService.selectdepet4(did);
    };
    @RequestMapping("/ContractMethod17")
    @ResponseBody
    //查询此部门有没有下级部门
    public List<Dept> selectxiadept(Integer jid){
        return deptService.selectxiadept(jid);
    }
    @RequestMapping("/ContractMethod18")
    @ResponseBody
    //根据角色名查询角色
    public List<Role> selectjueses(String jname,String did){
        return deptService.selectjueses(jname,did);
    };
    @RequestMapping("/ContractMethod19")
    @ResponseBody
    //查询此角色有没有被员工引用
    public List<UserRole> seelctuserrole(Integer jid){
        return deptService.seelctuserrole(jid);
    };
    @RequestMapping("/ContractMethod20")
    @ResponseBody
    //删除角色
    public void deletjuese(Long jid){
        deptService.deletjuese(jid);
    }
    @RequestMapping("/ContractMethod21")
    @ResponseBody
    //修改角色
    public void updaterow(String jname, Integer jid){
        deptService.updaterow(jname,jid);
    };
    @RequestMapping("/ContractMethod22")
    @ResponseBody
    public void updatejuss(Integer jid,Integer did){
      deptService.updatejuss(jid,did);
    }
}
